import type { OptionsOverrides, OptionsUnicorn, Rules, TypedFlatConfigItem } from '../types'

import { pluginUnicorn } from '../plugins'

export async function unicorn(options: OptionsUnicorn & OptionsOverrides = {}): Promise<TypedFlatConfigItem[]> {
    const {
        allRecommended = false,
        overrides = {},
    } = options

    return [
        {
            name: 'eslint/unicorn/rules',
            plugins: {
                unicorn: pluginUnicorn,
            },
            rules: {
                ...(allRecommended ? pluginUnicorn.configs.recommended.rules as Rules : {
                    'unicorn/consistent-empty-array-spread': 'error',
                    'unicorn/error-message': 'error',
                    'unicorn/escape-case': 'error',
                    'unicorn/new-for-builtins': 'error',
                    'unicorn/no-instanceof-array': 'error',
                    'unicorn/no-new-array': 'error',
                    'unicorn/no-new-buffer': 'error',
                    'unicorn/number-literal-case': 'error',
                    'unicorn/prefer-dom-node-text-content': 'error',
                    'unicorn/prefer-includes': 'error',
                    'unicorn/prefer-node-protocol': 'error',
                    'unicorn/prefer-number-properties': 'error',
                    'unicorn/prefer-string-starts-ends-with': 'error',
                    'unicorn/prefer-type-error': 'error',
                    'unicorn/throw-new-error': 'error',
                }),

                ...overrides,
            },
        },
    ]
}
